﻿@model Fly.Domain.Models.Post
@{
    ViewBag.Title =Model!=null ? Model.Title:"详情";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var comments = ViewBag.Comments as Fly.Domain.Infrastructure.GetPagingResponse<Fly.Domain.Models.Comment>;
}

@if (Model != null)
{

    <div class="main layui-clear">
        <div class="wrap">
            <div class="content detail">
                <h1>@Model.Title</h1>
                <div class="fly-tip fly-detail-hint" data-id="@Model.Id">
                    @if (Model.IsTop)
                    {
                        <span class="fly-tip-stick">置顶帖</span>
                    }
                    @if (Model.IsBoutique)
                    {
                        <span class="fly-tip-jing">精帖</span>
                    }
                    @if (Model.PostStatus == Fly.Domain.Models.PostStatus.Open)
                    {
                        <span>未结贴</span>
                    }
                    else
                    {
                        <span class="fly-tip-jie">已采纳</span>
                    }
                    @if (ViewBag.IsAdmin)
                    {
                        <span class="jie-admin" type="del" style="margin-left: 20px;">删除</span>
                        if (!Model.IsTop)
                        {
                            <span class="jie-admin" type="set" field="stick" rank="1">置顶</span>
                        }
                        else
                        {
                            <span class="jie-admin" type="set" field="stick" rank="0" style="background-color:#ccc;">取消置顶</span>
                        }
                        if (!Model.IsBoutique)
                        {
                            <span class="jie-admin" type="set" field="status" rank="1">加精</span>
                        }
                        else
                        {
                            <span class="jie-admin" type="set" field="status" rank="0" style="background-color:#ccc;">取消加精</span>
                        }
                    }

                    <div class="fly-list-hint">
                        <i class="iconfont" title="回答">&#xe60c;</i> @Model.CommentCount
                        <i class="iconfont" title="人气">&#xe60b;</i> @Model.Hits
                    </div>
                </div>
                <div class="detail-about">
                    <a class="jie-user" href="@Url.Action("Home","Account",new { userId=Model.UserId })">
                        <img src="@Model.User.HeadPortrait" alt="">
                        <cite>
                            @Model.User.Nickname
                            <em>@Model.TimeAgo</em>
                        </cite>
                    </a>
                    <div class="detail-hits" data-id="@Model.Id">
                        <span style="color:#FF7200">悬赏：@Model.Reward 飞吻</span>
                        @if (ViewBag.CurrentUserId == Model.UserId && Model.PostStatus == Fly.Domain.Models.PostStatus.Open)
                        {
                            <span class="jie-admin" type="edit"><a href="@Url.Action("Edit", "Post", new { postId = Model.Id })">编辑此贴</a></span>
                        }
                    </div>
                </div>

                <div class="detail-body photos" style="margin-bottom: 20px;">
                    @Model.Content
                </div>

                <a name="comment"></a>
                <h2 class="page-title">热忱回答<span>（<em id="jiedaCount">@Model.CommentCount</em>）</span></h2>

                <ul class="jieda photos" id="jieda">
                    @if (comments.IsSuccess)
                    {
                        var isAdopt = comments.Pages.Items.Any(p => p.IsAdopt);
                        foreach (var item in comments.Pages.Items)
                        {
                            <li data-id="@item.Id" class="jieda-daan">
                                <a name="item_@item.Ticks"></a>
                                <div class="detail-about detail-about-reply">
                                    <a class="jie-user" href="@Url.Action("Home","Account",new { userId=item.UserId })">
                                        <img src="@item.User.HeadPortrait" alt="">
                                        <cite>
                                            <i>@item.User.Nickname</i>
                                            @if (item.User.Id == Model.UserId)
                                            {
                                                <em>(楼主)</em>
                                            }
                                            @if (item.User.IsAdmin)
                                            {
                                                <em style="color:#5FB878">(管理员)</em>
                                            }
                                            @if (!string.IsNullOrEmpty(item.User.Title))
                                            {
                                                <em style="color:#FF9E3F">（@item.User.Title）</em>
                                            }
                                            @if (item.User.IsDisabled)
                        {
                                                <em style="color:#999">（该号已被封）</em>
                                            }
                                        </cite>
                                    </a>
                                    <div class="detail-hits">
                                        <span>@item.TimeAgo</span>
                                    </div>
                                    @if (item.IsAdopt)
                        {
                                        <i class="iconfont icon-caina" title="最佳答案"></i>
                                    }
                                </div>
                                <div class="detail-body jieda-body">
                                    @item.Content
                                </div>
                                <div class="jieda-reply">
                                    @{ 
                                        var zanok = item.IsLike ? "zanok" : "";
                                    }
                                    <span class="jieda-zan   @zanok" type="zan"><i class="iconfont icon-zan"></i><em>@item.Like</em></span>
                                    <span type="reply"><i class="iconfont icon-svgmoban53"></i>回复</span>
                                    <div class="jieda-admin">
                                        <!--<span type="edit">编辑</span>
                                        <span type="del">删除</span>-->
                                        @if (Model.UserId == ViewBag.CurrentUserId && !isAdopt && item.UserId != Model.UserId)
                                        {
                                            <span class="jieda-accept" type="accept">采纳</span>
                                        }
                                    </div>
                                </div>
                            </li>
                        }
                    }
                    else
                    {
                        <li class="fly-none">没有任何回答</li>
                    }

                </ul>

                <div class="layui-form layui-form-pane">
                    <form action="@Url.Action("Reply","Post")" method="post">
                        <div class="layui-form-item layui-form-text">
                            <div class="layui-input-block">
                                <textarea id="L_content" name="content" required lay-verify="required" placeholder="我要回答'" class="layui-textarea fly-editor" style="height: 150px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name="id" value="@Model.Id">
                            <button class="layui-btn" lay-filter="*" lay-submit>提交回答</button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
        <div class="edge">

            <!--最近热帖 TOP8-->
            @{Html.RenderAction("LoadHotPostTopFifty");}
            <!--近期热议 TOP8-->
            @{Html.RenderAction("LoadHotCommentTopFifty");}

        </div>
    </div>
                }
                else
                {
                    <h2 class="page-title">404</h2>
                    <div class="fly-none">该问题并不存在，可能已被删除</div>
                }
@section scripts{
    <script>
    </script>

}